/**
 * 
 */
package com.hfjyz.registration.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.hfjyz.registration.contants.ExamContants;

/**
 *
 */
public class ExamSelectInterceptor extends HandlerInterceptorAdapter {
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle
	 * (javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String reqUrl = request.getServletPath();
		if (excludeUrls != null && excludeUrls.size() > 0) {
			for (String url : excludeUrls) {
				if (reqUrl.contains(url)) {
					return super.preHandle(request, response, handler);
				}
			}
		}
		if (request.getSession().getAttribute(
				ExamContants.SESSION_KEY_EXAM_INFO) == null) {
			request.getRequestDispatcher("/announcementSelect.action").forward(
					request, response);
			return false;
		}
		return super.preHandle(request, response, handler);
	}

	/**
	 * @return the excludeUrls
	 */
	public List<String> getExcludeUrls() {
		return excludeUrls;
	}

	/**
	 * @param excludeUrls
	 *            the excludeUrls to set
	 */
	public void setExcludeUrls(List<String> excludeUrls) {
		this.excludeUrls = excludeUrls;
	}

	private List<String> excludeUrls;

}
